package cn.hrc.controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.io.IOException;
import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

//不管那一层的异常，统一由
@ControllerAdvice //advice 通知
public class ErrController {
    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public String doInt(Exception e, Model model){
        model.addAttribute("msg","主键编码重复:\t"+e.getMessage());
        return "err";
    }
    @ExceptionHandler(SQLException.class)
    public String doException(Exception e, Model model){
        model.addAttribute("msg","SQL:\t"+e.getMessage());
        return "err";
    }
    @ExceptionHandler(IOException.class)
    public String doIOException(Exception e, Model model){
        model.addAttribute("msg","网络故障:\t"+e.getMessage());
    return "err";
    }
    @ExceptionHandler(Exception.class)
    public String doError(Exception e, Model model){
        model.addAttribute("msg",e.getMessage());
        return "err";
    }
}
